package ystp.controller;

import jxl.Workbook;
import jxl.format.UnderlineStyle;
import jxl.write.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import ystp.model.*;
import ystp.service.*;
import ystp.support.JsonResult;
import ystp.support.StringHandle;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.text.SimpleDateFormat;
import java.util.*;

@RestController
@RequestMapping("shengchanqiyetoupiao")
public class ShengchanqiyelinxuantoupiaoController {

    public Logger log = LoggerFactory.getLogger(ShengchanqiyelinxuantoupiaoController.class);

    @Resource
    public YsxiangmuService ddYsxiangmuService;
    @Resource
    public YsrenyuanfenpeiService ddYsrenyuanfenpeiService;
    @Resource
    public ShengchanqiyelinxuanService ddShengchanqiyelinxuanService;
    @Resource
    public ShengchanqiyelinxuantoupiaoService ddService;
    @Resource
    YsuserService ddYsuserService;


    @RequestMapping("vote")
    public JsonResult<?> vote(@RequestParam("id") String ppDetailId,
                                 @RequestParam("pinzhong") int ppPinzhong,
                                 @RequestParam("pingui") String ppPingui,
                                 @RequestParam("lunci") int ppLunci,
                                 @RequestParam("userid") String ppuserId,
                                 @RequestParam("result") String ppresult){
        try {
            Shengchanqiyelinxuantoupiao mmShengchanqiyelinxuantoupiao=new Shengchanqiyelinxuantoupiao();
            Shengchanqiyelinxuan mmShengchanqiyelinxuan=ddShengchanqiyelinxuanService.findOne(ppDetailId);

            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(mmShengchanqiyelinxuan.getXiangmuid());
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            String mmXiangmuleixing = mmYsxiangmu.getXiangmuleixing();//项目类型ID 11 12 13 14
            String mmPinguixuhao = mmShengchanqiyelinxuan.getPinguixuhao();

            List<Ysrenyuanfenpei> listfenpei = ddYsrenyuanfenpeiService.findbyUserIDandXiangmuId(ppuserId,mmShengchanqiyelinxuan.getXiangmuid());
            if(listfenpei.get(0).getIssubmit()==1){
                return JsonResult.getErrorResult("表决失败，当前投票项已提交");
            }

            if("1".equals(ppresult)) {

                    //备注2：淘汰
                    String mmBeizhu2 = mmShengchanqiyelinxuan.getBeizhu2();
                    if (mmBeizhu2.equals("1")){
                        return JsonResult.getErrorResult("表决失败，该企业无法同意");
                    }

                    //备注3：3和2选1
                    String mmBeizhu3 = mmShengchanqiyelinxuan.getBeizhu3();
                    int mmPassCount = ddService.countPinguiPass(mmShengchanqiyelinxuan.getXiangmuid(),ppPingui,ppuserId,ppLunci);
                    if (mmBeizhu3.equals("2")){
                        if (mmPassCount>0){
                            return JsonResult.getErrorResult("表决失败，规格序号【"+mmPinguixuhao+"】仅2选1");
                        }
                    }else if(mmBeizhu3.equals("3")){
                        if (mmPassCount>0){
                            return JsonResult.getErrorResult("表决失败，规格序号【"+mmPinguixuhao+"】仅3选1");
                        }
                    }else if(mmBeizhu3.equals("4")){
                        String Detail1 = "7b9a7e57-3e90-4070-b361-0aa7edc7fa1d";
                        String Detail2 = "f63103b5-6f85-4159-bd48-f90e42aabf01";
                        int mmDetailPassCount = 0;
                        if (ppDetailId.equals(Detail1)){
                            mmDetailPassCount = ddService.countDetailPass(Detail2,ppuserId,ppLunci);
                        }else if (ppDetailId.equals(Detail2)){
                            mmDetailPassCount = ddService.countDetailPass(Detail1,ppuserId,ppLunci);
                        }

                        if (mmDetailPassCount>0){
                            return JsonResult.getErrorResult("规格序号【369】,【370】原研,至多二选一");
                        }
                    }else if(mmBeizhu3.equals("5")){
                        String Detail1 = "46b38c8a-9c93-464c-8e9a-e7fb3587b599";
                        String Detail2 = "1b846e8a-a21a-4014-a551-b06a7fac96d9";
                        int mmDetailPassCount = 0;
                        if (ppDetailId.equals(Detail1)){
                            mmDetailPassCount = ddService.countDetailPass(Detail2,ppuserId,ppLunci);
                        }else if (ppDetailId.equals(Detail2)){
                            mmDetailPassCount = ddService.countDetailPass(Detail1,ppuserId,ppLunci);
                        }

                        if (mmDetailPassCount>0){
                            return JsonResult.getErrorResult("规格序号【369】,【370】原研,至多二选一");
                        }
                    }

                    if (ddService.checkexistByUserId(ppDetailId, ppuserId) != null) {
                        String mmId = ddService.checkexistByUserId(ppDetailId, ppuserId).getId();
                        mmShengchanqiyelinxuantoupiao.setId(mmId);
                        mmShengchanqiyelinxuantoupiao.setDetailid(ppDetailId);
                        mmShengchanqiyelinxuantoupiao.setPinzhong(ppPinzhong);
                        mmShengchanqiyelinxuantoupiao.setPingui(ppPingui);
                        mmShengchanqiyelinxuantoupiao.setUserid(ppuserId);
                        mmShengchanqiyelinxuantoupiao.setLunci(ppLunci);
                        mmShengchanqiyelinxuantoupiao.setResult(ppresult);
                        mmShengchanqiyelinxuantoupiao.setCreatetime(new Date());
                        return ddService.modify(mmShengchanqiyelinxuantoupiao) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }else {
                        mmShengchanqiyelinxuantoupiao.setId(UUID.randomUUID().toString());
                        mmShengchanqiyelinxuantoupiao.setDetailid(ppDetailId);
                        mmShengchanqiyelinxuantoupiao.setPinzhong(ppPinzhong);
                        mmShengchanqiyelinxuantoupiao.setPingui(ppPingui);
                        mmShengchanqiyelinxuantoupiao.setUserid(ppuserId);
                        mmShengchanqiyelinxuantoupiao.setLunci(ppLunci);
                        mmShengchanqiyelinxuantoupiao.setResult(ppresult);
                        mmShengchanqiyelinxuantoupiao.setCreatetime(new Date());
                        return ddService.add(mmShengchanqiyelinxuantoupiao) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }

                }else {
                    if (ddService.checkexistByUserId(ppDetailId, ppuserId) != null) {
                        String mmId = ddService.checkexistByUserId(ppDetailId, ppuserId).getId();
                        mmShengchanqiyelinxuantoupiao.setId(mmId);
                        mmShengchanqiyelinxuantoupiao.setDetailid(ppDetailId);
                        mmShengchanqiyelinxuantoupiao.setPinzhong(ppPinzhong);
                        mmShengchanqiyelinxuantoupiao.setPingui(ppPingui);
                        mmShengchanqiyelinxuantoupiao.setUserid(ppuserId);
                        mmShengchanqiyelinxuantoupiao.setLunci(ppLunci);
                        mmShengchanqiyelinxuantoupiao.setResult(ppresult);
                        mmShengchanqiyelinxuantoupiao.setCreatetime(new Date());
                        return ddService.modify(mmShengchanqiyelinxuantoupiao) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }else {
                        mmShengchanqiyelinxuantoupiao.setId(UUID.randomUUID().toString());
                        mmShengchanqiyelinxuantoupiao.setDetailid(ppDetailId);
                        mmShengchanqiyelinxuantoupiao.setPinzhong(ppPinzhong);
                        mmShengchanqiyelinxuantoupiao.setPingui(ppPingui);
                        mmShengchanqiyelinxuantoupiao.setUserid(ppuserId);
                        mmShengchanqiyelinxuantoupiao.setLunci(ppLunci);
                        mmShengchanqiyelinxuantoupiao.setResult(ppresult);
                        mmShengchanqiyelinxuantoupiao.setCreatetime(new Date());
                        return ddService.add(mmShengchanqiyelinxuantoupiao) == true ? JsonResult.getSuccessResult("表决成功")
                                : JsonResult.getErrorResult("表决失败");
                    }
                }
        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiyetoupiao/vote:error",e);
            return JsonResult.getErrorResult("shengchanqiyetoupiao/vote:error " + e.getMessage());
        }
    }

    @RequestMapping("vote_jicai")
    public JsonResult<?> votejicai(@RequestParam("xiangmuid") String ppXiangmuId,
                                  @RequestParam("userid") String ppUserId){
        try {

            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppXiangmuId);
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }

            int mmLunci = mmYsxiangmu.getLunci();

            List<Shengchanqiyelinxuan> mmList=ddShengchanqiyelinxuanService.findJicai(ppXiangmuId);
            for(Shengchanqiyelinxuan mmShengchanqiyelinxuan :mmList){
                String mmDetailId=mmShengchanqiyelinxuan.getId();
                Shengchanqiyelinxuantoupiao mmShengchanqiyelinxuantoupiao=ddService.checkexistByUserId(mmDetailId,ppUserId);
                if(mmShengchanqiyelinxuantoupiao!=null){
                    mmShengchanqiyelinxuantoupiao.setResult("1");
                    mmShengchanqiyelinxuantoupiao.setLunci(mmLunci);
                    ddService.modify(mmShengchanqiyelinxuantoupiao);
                }else {
                    Shengchanqiyelinxuantoupiao mmShengchanqiyelinxuantoupiao2=new Shengchanqiyelinxuantoupiao();
                    String mmId=UUID.randomUUID().toString();
                    mmShengchanqiyelinxuantoupiao2.setId(mmId);
                    mmShengchanqiyelinxuantoupiao2.setDetailid(mmDetailId);
                    mmShengchanqiyelinxuantoupiao2.setUserid(ppUserId);
                    mmShengchanqiyelinxuantoupiao2.setResult("1");
                    mmShengchanqiyelinxuantoupiao2.setCreatetime(new Date());
                    mmShengchanqiyelinxuantoupiao2.setLunci(mmLunci);
                    mmShengchanqiyelinxuantoupiao2.setPinzhong(Integer.parseInt(mmShengchanqiyelinxuan.getPinzhongbianhao()));
                    mmShengchanqiyelinxuantoupiao2.setPingui(mmShengchanqiyelinxuan.getPinguixuhao());
                    ddService.add(mmShengchanqiyelinxuantoupiao2);
                }
            }

            return  JsonResult.getSuccessResult("表决成功");

        }catch (Exception e) {
            e.printStackTrace();
            log.error("kangjunyaowujieguo/votesure:error",e);
            return JsonResult.getErrorResult("kangjunyaowujieguo/votesure:error " + e.getMessage());
        }
    }

    @RequestMapping("submit")
    public JsonResult<?> submit(@RequestParam("xiangmuid") String ppXiangmuId,
                              @RequestParam("userid") String ppUserId){
        try {
            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppXiangmuId);
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            List<Ysrenyuanfenpei> list=ddYsrenyuanfenpeiService.findbyUserIDandXiangmuId(ppUserId,ppXiangmuId);
            if(list.size()<1){
                return JsonResult.getErrorResult("提交失败，人员-项目分配信息不存在");
            }

            int mmLunci = mmYsxiangmu.getLunci();
            String mmXiangmuleixing = mmYsxiangmu.getXiangmuleixing();

            //集采数与集采通过数
            int mmJicaishu = ddShengchanqiyelinxuanService.countJicai(ppXiangmuId);
            int mmJicaiPass = ddService.countJicaiPass(ppXiangmuId,ppUserId);
            boolean mmJicaiOk = true;//集采是否全勾选
            if (mmJicaishu!=mmJicaiPass){
                mmJicaiOk = false;
            }

            int mmPass = ddService.countPass(ppXiangmuId,ppUserId);

            List<Map<String,Object>> mmPingguiList = ddShengchanqiyelinxuanService.findPinguiAll(ppXiangmuId,1,99999);

            if (mmXiangmuleixing.equals("11")){
                if (!mmJicaiOk){
                    return JsonResult.getErrorResult("提交失败，集采药未勾选完毕");
                }
                for (int i=0;i<mmPingguiList.size();i++){
                    String mmPingui = mmPingguiList.get(i).get("pinguixuhao").toString();
                    //224,533,787,789排除
                    if (!mmPingui.equals("224")&&!mmPingui.equals("533")&&!mmPingui.equals("787")&&!mmPingui.equals("789")){
                        int mmCountPinguiPass = ddService.countPingguiPass(mmPingui,ppUserId);
                        if (mmCountPinguiPass<1){
                            return JsonResult.getErrorResult("提交失败，【"+mmPingui+"】未勾选企业");
                        }
                    }
                }
                if (mmPass<1205){
                    return JsonResult.getErrorResult("提交失败，勾选企业数未达1205个");
                }
            }else if(mmXiangmuleixing.equals("12")){
                if (mmPass<52){
                    return JsonResult.getErrorResult("提交失败，勾选企业数未达52个");
                }
            }else if(mmXiangmuleixing.equals("13")){
                for (int i=0;i<mmPingguiList.size();i++){
                    String mmPingui = mmPingguiList.get(i).get("pinguixuhao").toString();
                    int mmCountPinguiPass = ddService.countPingguiPass(mmPingui,ppUserId);
                    if (mmCountPinguiPass<1){
                        return JsonResult.getErrorResult("提交失败，【"+mmPingui+"】未勾选企业");
                    }
                }
                if (mmPass<251){
                    return JsonResult.getErrorResult("提交失败，勾选企业数未达251个");
                }
            }else if(mmXiangmuleixing.equals("14")){
                if (mmPass<13){
                    return JsonResult.getErrorResult("提交失败，勾选企业数未达13个");
                }
            }

            Ysrenyuanfenpei mmRenyuanfenpei=ddYsrenyuanfenpeiService.findOne(list.get(0).getId());
            mmRenyuanfenpei.setIssubmit(1);
            mmRenyuanfenpei.setUpdatetime(new Date());
            mmRenyuanfenpei.setUpdateby(ppUserId);
            return ddYsrenyuanfenpeiService.update(mmRenyuanfenpei)==true? JsonResult.getSuccessResult("提交成功")
                    : JsonResult.getErrorResult("提交失败");
        }catch (Exception e) {
            e.printStackTrace();
            log.error("shengchanqiyetoupiao/submit:error",e);
            return JsonResult.getErrorResult("shengchanqiyetoupiao/submit:error " + e.getMessage());
        }
    }

    @RequestMapping("getResultCount")
    public JsonResult<?> getResultCount(@RequestParam("xiangmuid") String ppXiangmuId,
                                             @RequestParam("userid") String ppUserId){
        try {

            Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppXiangmuId);
            if(mmYsxiangmu.getIsactived()!=1){
                return JsonResult.getErrorResult("表决失败，投票尚未启动");
            }
            List<Ysrenyuanfenpei> list=ddYsrenyuanfenpeiService.findbyUserIDandXiangmuId(ppUserId,ppXiangmuId);
            if(list.size()<1){
                return JsonResult.getErrorResult("提交失败，人员-项目分配信息不存在");
            }

            int mmLunci = mmYsxiangmu.getLunci();
            String mmXiangmuleixing = mmYsxiangmu.getXiangmuleixing();

            int mmPass = ddService.countPass(ppXiangmuId,ppUserId);
            int mmJicaiPass = ddService.countJicaiPass(ppXiangmuId,ppUserId);

            int mmJicaishu = ddShengchanqiyelinxuanService.countJicai(ppXiangmuId);

            Map<String, Object> mmMap = new HashMap<String, Object>();
            mmMap.put("qiyepass", mmPass);
            mmMap.put("jicaipass", mmJicaiPass);
            mmMap.put("jicaishengyu", mmJicaishu-mmJicaiPass);
            return JsonResult.getSuccessResult(mmMap);
        }catch (Exception e) {
            e.printStackTrace();
            log.error("kangjunyaowujieguo/getKangJunResultCount:error",e);
            return JsonResult.getErrorResult("kangjunyaowujieguo/getKangJunResultCount:error " + e.getMessage());
        }
    }

    @RequestMapping("qianzibiao")
    public void qianzibiao(HttpServletRequest request, HttpServletResponse response,
                             @RequestParam("xiangmuid") String ppxiangmuid,
                             @RequestParam("xiangmuleixing") String ppxiangmuleixing,
                             @RequestParam("userid") String ppuserid){



        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        Ysuser mmuser=ddYsuserService.findOne(ppuserid);
        String mmusername=mmuser.getUsername();
        Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuid);
        Integer mmlunci=mmYsxiangmu.getLunci();

        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle="";
            String tmptitle="";
            if(mmlunci==1){
                if("11".equals(ppxiangmuleixing)){
                    wenjiantitle = "1药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选投票表（平台挂网及军供站配送）"; // 标题
                }
                if("12".equals(ppxiangmuleixing)){
                    wenjiantitle = "2药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选投票表（线下和备案）"; // 标题
                }
                if("13".equals(ppxiangmuleixing)){
                    wenjiantitle = "3药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选投票表（国家谈判）"; // 标题
                }
                if("14".equals(ppxiangmuleixing)){
                    wenjiantitle = "4药品生产企业遴选"+mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选投票表（南京市生物创新）"; // 标题
                }
            }else{
                if("11".equals(ppxiangmuleixing)){
                    wenjiantitle = "1药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选补充投票表（平台挂网及军供站配送）"; // 标题
                }
                if("12".equals(ppxiangmuleixing)){
                    wenjiantitle = "2药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选补充投票表（线下和备案）"; // 标题
                }
                if("13".equals(ppxiangmuleixing)){
                    wenjiantitle = "3药品生产企业遴选" +mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选补充投票表（国家谈判）"; // 标题
                }
                if("14".equals(ppxiangmuleixing)){
                    wenjiantitle = "4药品生产企业遴选"+mmusername+"委员投票表"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选补充投票表（南京市生物创新）"; // 标题
                }
            }

            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,500); //第二行高度
            wsheet.mergeCells(0, 0, 24, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0,5); //品种宽度
            wsheet.setColumnView(1,10); //分类宽度
            wsheet.setColumnView(2,10); //品名宽度
            wsheet.setColumnView(3,5); //剂型宽度
            wsheet.setColumnView(4,5); //序号宽度
            wsheet.setColumnView(5,12); //名称宽度
            wsheet.setColumnView(6,10); //规格单位
            wsheet.setColumnView(7,5); //单位类别
            wsheet.setColumnView(8,5); //医保宽度
            wsheet.setColumnView(9,5); //1宽度
            wsheet.setColumnView(10,5); //2宽度
            wsheet.setColumnView(11,5); //3宽度
            wsheet.setColumnView(12,5); //1宽度
            wsheet.setColumnView(13,5); //2宽度
            wsheet.setColumnView(14,5); //3宽度
            wsheet.setColumnView(15,5); //4宽度
            wsheet.setColumnView(16,6); //1宽度
            wsheet.setColumnView(17,5); //2宽度
            wsheet.setColumnView(18,4); //基药宽度
            wsheet.setColumnView(19,4); //集采宽度
            wsheet.setColumnView(20,4); //1宽度
            wsheet.setColumnView(21,4); //2宽度
            wsheet.setColumnView(22,11); //产品宽度
            wsheet.setColumnView(23,12); //生产企业宽度
            wsheet.setColumnView(24,8); //表决意见宽度
            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);

            // 不需要边框和居中的样式
            WritableFont wfont2 = new WritableFont(WritableFont.ARIAL, 8,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 垂直居中
            wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setWrap(true);
            //  在  1 列  2 行 写入内容
            wsheet.addCell(new Label(0, 1, "投票人(签字):投票内容已核对无误。"+mmusername,wcfFC2));
            // 把  0 列 2 行 到 9 列 2 行合并
            wsheet.mergeCells(0, 1, 16, 1);

            wsheet.addCell(new Label(17, 1, "投票日期:"+StringHandle.shorttiemString(),wcfFC2));
            wsheet.mergeCells(17, 1, 24, 1);
            // 第三行内容
            wsheet.addCell(new Label(0, 2, "品种序号",wcfFC));
            wsheet.mergeCells(0, 2, 0, 3);
            wsheet.addCell(new Label(1, 2, "药品分类",wcfFC));
            wsheet.mergeCells(1, 2, 1, 3);
            wsheet.addCell(new Label(2, 2, "药品品名",wcfFC));
            wsheet.mergeCells(2, 2, 2, 3);
            wsheet.addCell(new Label(3, 2, "剂型",wcfFC));
            wsheet.mergeCells(3, 2, 3, 3);
            wsheet.addCell(new Label(4, 2, "序号",wcfFC));
            wsheet.mergeCells(4, 2, 4, 3);
            wsheet.addCell(new Label(5, 2, "药品名称",wcfFC));
            wsheet.mergeCells(5, 2, 5, 3);
            wsheet.addCell(new Label(6, 2, "规格",wcfFC));
            wsheet.mergeCells(6, 2, 6, 3);
            wsheet.addCell(new Label(7, 2, "单位",wcfFC));
            wsheet.mergeCells(7, 2, 7, 3);
            wsheet.addCell(new Label(8, 2, "医保类别",wcfFC));
            wsheet.mergeCells(8, 2, 8, 3);

            wsheet.addCell(new Label(9, 2, "上级检查通报",wcfFC));
            wsheet.addCell(new Label(10, 2, "未挂网",wcfFC));
            wsheet.addCell(new Label(11, 2, "无配送企业",wcfFC));

            wsheet.addCell(new Label(12, 2, "原国谈",wcfFC));
            wsheet.addCell(new Label(13, 2, "通过一致性评价",wcfFC));
            wsheet.addCell(new Label(14, 2, "国家保密配方",wcfFC));
            wsheet.addCell(new Label(15, 2, "中药保护品种",wcfFC));

            wsheet.addCell(new Label(16, 2, "价格（元）",wcfFC));
            wsheet.addCell(new Label(17, 2, "原研",wcfFC));

            wsheet.addCell(new Label(18, 2, "基药",wcfFC));
            wsheet.mergeCells(18, 2, 18, 3);
            wsheet.addCell(new Label(19, 2, "集采",wcfFC));
            wsheet.mergeCells(19, 2, 19, 3);
            wsheet.addCell(new Label(20, 2, "院本部",wcfFC));
            wsheet.mergeCells(20, 2, 19, 3);
            wsheet.addCell(new Label(21, 2, "秦淮",wcfFC));
            wsheet.mergeCells(21, 2, 21, 3);
            wsheet.addCell(new Label(22, 2, "产品编码",wcfFC));
            wsheet.mergeCells(22, 2, 22, 3);
            wsheet.addCell(new Label(23, 2, "生产企业",wcfFC));
            wsheet.mergeCells(23, 2, 23, 3);
            wsheet.addCell(new Label(24, 2, "表决意见",wcfFC));
            wsheet.mergeCells(24, 2, 24, 3);


            // 第四行内容
            wsheet.addCell(new Label(9, 3, "淘汰原则",wcfFC));
            wsheet.mergeCells(9, 3, 11, 3);
            wsheet.addCell(new Label(12, 3, "绝对优先",wcfFC));
            wsheet.mergeCells(12, 3, 15, 3);
            wsheet.addCell(new Label(16, 3, "相对优先",wcfFC));
            wsheet.mergeCells(16, 3, 17, 3);


            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);


            int mmKaishihang1 = 4;
            int mmKaishihang2 = 4;
            int mmKaishihang3 = 4;

            List<Map<String,Object>> mmPinzhongAll = ddShengchanqiyelinxuanService.findPinzhong(ppxiangmuid,mmlunci,"","","","",1,9999);
            int a=1;
            for (Map<String, Object> mmPinzhongMap : mmPinzhongAll) {

                int mmPinzhongHebingshu = 0;
                String mmPinzhongOne = mmPinzhongMap.get("pinzhongbianhao").toString();
                String mmYaopinpinming = mmPinzhongMap.get("yaopinpinming").toString();
                String mmbeizhu1 = mmPinzhongMap.get("beizhu1").toString();

                List<Map<String,Object>> mmPinguilist = ddShengchanqiyelinxuanService.findPinguiByPinzhongLunci(ppxiangmuid,mmPinzhongOne,mmlunci);
                if (mmPinguilist.size()>0){
                    mmPinzhongHebingshu = mmPinguilist.size()-1;
                }
                List<Map<String,Object>> mmPinguiFenlei = ddShengchanqiyelinxuanService.findPinguiFenleiLunci(ppxiangmuid,mmPinzhongOne,mmlunci);

                for (Map<String, Object> mmPinguiMap : mmPinguiFenlei) {

                    a=a+1;
                    String mmPinguiOne = mmPinguiMap.get("pinguixuhao").toString();
                    String mmYaopinmingcheng = mmPinguiMap.get("yaopinmingcheng").toString();
                    String mmGuige = mmPinguiMap.get("guige").toString();
                    String mmDanwei = mmPinguiMap.get("danwei").toString();
                    String mmYibaoleibie = mmPinguiMap.get("yibaoleibie").toString();
                    String mmjixing = mmPinguiMap.get("jixing").toString();

                    int mmHebingshu = 0;

                    List<Map<String,Object>> mmShengchanqiyelist = ddShengchanqiyelinxuanService.findShengchanqiyeByPinguiResult(ppxiangmuid,mmPinguiOne,ppuserid,mmlunci);
                    if (mmShengchanqiyelist.size()>0){
                        mmHebingshu = mmShengchanqiyelist.size()-1;
                    }
                    int pg=0;
                    for (Map<String, Object> mmMap : mmShengchanqiyelist) {
                        pg=pg+1;

                        String mmjianchatongbao = mmMap.get("jianchatongbao")==null ? "" :mmMap.get("jianchatongbao").toString();
                        String mmweiguawang=mmMap.get("weiguawang")==null ? "" :mmMap.get("weiguawang").toString();
                        String mmwupeisongqiye=mmMap.get("wupeisongqiye")==null ? "" :mmMap.get("wupeisongqiye").toString();
                        String mmyuanguotan=mmMap.get("yuanguotan")==null ? "" :mmMap.get("yuanguotan").toString();
                        String mmyizhixingpingjia=mmMap.get("yizhixingpingjia")==null ? "" :mmMap.get("yizhixingpingjia").toString();
                        String mmbaomipeifang=mmMap.get("baomipeifang")==null ? "" :mmMap.get("baomipeifang").toString();
                        String mmbaohupinzhong=mmMap.get("baohupinzhong")==null ? "" :mmMap.get("baohupinzhong").toString();
                        String mmjiage=mmMap.get("jiage")==null ? "" :mmMap.get("jiage").toString();
                        String mmyuanyan=mmMap.get("yuanyan")==null ? "" :mmMap.get("yuanyan").toString();
                        String mmjiyao=mmMap.get("jiyao")==null ? "" :mmMap.get("jiyao").toString();
                        String mmjicai=mmMap.get("jicai")==null ? "" :mmMap.get("jicai").toString();
                        String mmyuanbenbu=mmMap.get("yuanbenbu")==null ? "" :mmMap.get("yuanbenbu").toString();
                        String mmqinhuai=mmMap.get("qinhuai")==null ? "" :mmMap.get("qinhuai").toString();
                        String mmchanpinbianma=mmMap.get("chanpinbianma")==null ? "" :mmMap.get("chanpinbianma").toString();
                        String mmshengchanqiye=mmMap.get("shengchanqiye")==null ? "" :mmMap.get("shengchanqiye").toString();
                        String mmbeizhu=mmMap.get("beizhu")==null ? "" :mmMap.get("beizhu").toString();
                        String mmresult=mmMap.get("result")==null ? "" :mmMap.get("result").toString();

                        String mmyijian="";
                        if("1".equals(mmresult)){
                            mmyijian="同意";
                        }else if("0".equals(mmresult)){
                            mmyijian="不同意";
                        }else {
                            mmyijian="不同意";
                        }

                        WritableCellFormat alignStyle = new WritableCellFormat(); //单元格样式
                        alignStyle.setBackground(Colour.GREEN); //背静色

                        wsheet.addCell(new Label(9, mmKaishihang3,mmjianchatongbao,wcfFC));
                        wsheet.addCell(new Label(10, mmKaishihang3,mmweiguawang,wcfFC));
                        wsheet.addCell(new Label(11, mmKaishihang3,mmwupeisongqiye,wcfFC));
                        wsheet.addCell(new Label(12, mmKaishihang3,mmyuanguotan,wcfFC));
                        wsheet.addCell(new Label(13, mmKaishihang3,mmyizhixingpingjia,wcfFC));
                        wsheet.addCell(new Label(14, mmKaishihang3,mmbaomipeifang,wcfFC));
                        wsheet.addCell(new Label(15, mmKaishihang3,mmbaohupinzhong,wcfFC));
                        wsheet.addCell(new Label(16, mmKaishihang3,mmjiage,wcfFC));
                        wsheet.addCell(new Label(17, mmKaishihang3,mmyuanyan,wcfFC));
                        wsheet.addCell(new Label(18, mmKaishihang3,mmjiyao,wcfFC));
                        wsheet.addCell(new Label(19, mmKaishihang3,mmjicai,wcfFC));
                        wsheet.addCell(new Label(20, mmKaishihang3,mmyuanbenbu,wcfFC));
                        wsheet.addCell(new Label(21, mmKaishihang3,mmqinhuai,wcfFC));
                        wsheet.addCell(new Label(22, mmKaishihang3,mmchanpinbianma,wcfFC));
                        wsheet.addCell(new Label(23, mmKaishihang3,mmshengchanqiye,wcfFC));
                        wsheet.addCell(new Label(24, mmKaishihang3,mmyijian,wcfFC));
                        mmKaishihang3 = mmKaishihang3+1;
                    }
                    wsheet.addCell(new Label(3, mmKaishihang2, mmjixing,wcfFC));
                    wsheet.addCell(new Label(4, mmKaishihang2, mmPinguiOne,wcfFC));
                    wsheet.addCell(new Label(5, mmKaishihang2, mmYaopinmingcheng,wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang2, mmGuige,wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang2, mmDanwei,wcfFC));
                    wsheet.addCell(new Label(8, mmKaishihang2, mmYibaoleibie,wcfFC));
                    wsheet.mergeCells(3, mmKaishihang2, 3, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(4, mmKaishihang2, 4, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(5, mmKaishihang2, 5, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(6, mmKaishihang2, 6, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(7, mmKaishihang2, 7, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(8, mmKaishihang2, 8, mmKaishihang2+mmHebingshu);
                    mmKaishihang2 = mmKaishihang2+mmHebingshu+1;
                }
                wsheet.addCell(new Label(0, mmKaishihang1, mmPinzhongOne,wcfFC));
                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(1, mmKaishihang1, mmbeizhu1,wcfFC));
                wsheet.mergeCells(1, mmKaishihang1, 1, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(2, mmKaishihang1, mmYaopinpinming,wcfFC));
                wsheet.mergeCells(2, mmKaishihang1, 2, mmKaishihang1+mmPinzhongHebingshu);
                mmKaishihang1 = mmKaishihang1+mmPinzhongHebingshu+1;

            }


            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

    @RequestMapping("huizongbiao")
    public void huizongbiao(HttpServletRequest request, HttpServletResponse response,
                            @RequestParam("xiangmuid") String ppxiangmuId,
                            @RequestParam("xiangmuleixing") String ppxiangmuleixing){
        Ysxiangmu mmYsxiangmu=ddYsxiangmuService.findOne(ppxiangmuId);
        int mmLunci = mmYsxiangmu.getLunci();
        List<Ysrenyuanfenpei> mmUserList=ddYsrenyuanfenpeiService.findUserByXiangmuId(ppxiangmuId);

        List<Map<String,Object>> mmPinzhongAll = ddShengchanqiyelinxuanService.findPinzhongCustom(ppxiangmuId,1,9999);


        response.reset();
        response.setContentType("application/x-download;charset=utf-8");
        OutputStream os=null;
        WritableWorkbook wbook=null;

        try {
            os = new BufferedOutputStream(response.getOutputStream());//得到输出流的语句
            //response.getOutputStream();// 取得输出流
            response.reset();// 清空输出流
            SimpleDateFormat mmDateFormat = new SimpleDateFormat("yyyyMMdd-HHmmss");
            String wenjiantitle="";
            String tmptitle="";
            if(mmLunci==1){
                if("11".equals(ppxiangmuleixing)){
                    wenjiantitle = "1药品生产企业遴选表决结果"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选表决结果（平台挂网及军供站配送）"; // 标题
                }
                if("12".equals(ppxiangmuleixing)){
                    wenjiantitle = "2药品生产企业遴选表决结果"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选表决结果（线下和备案）"; // 标题
                }
                if("13".equals(ppxiangmuleixing)){
                    wenjiantitle = "3药品生产企业遴选表决结果"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选表决结果（国家谈判）"; // 标题
                }
                if("14".equals(ppxiangmuleixing)){
                    wenjiantitle = "4药品生产企业遴选表决结果"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选表决结果（南京市生物创新）"; // 标题
                }
            }else{
                if("11".equals(ppxiangmuleixing)){
                    wenjiantitle = "1药品生产企业遴选补充表决结果"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选补充表决结果（平台挂网及军供站配送）"; // 标题
                }
                if("12".equals(ppxiangmuleixing)){
                    wenjiantitle = "2药品生产企业遴选补充表决结果"; //文件名
                    tmptitle = "《东部战区总医院基本用药目录》药品生产企业遴选补充表决结果（线下和备案）"; // 标题
                }
                if("13".equals(ppxiangmuleixing)){
                    wenjiantitle = "3药品生产企业遴选补充表决结果"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选补充表决结果（国家谈判）"; // 标题
                }
                if("14".equals(ppxiangmuleixing)){
                    wenjiantitle = "4药品生产企业遴选补充表决结果"; //文件名
                    tmptitle = "《东部战区总医院医保约定采购目录》药品生产企业遴选补充表决结果（南京市生物创新）"; // 标题
                }
            }
            response.setHeader("Content-disposition", "attachment; filename=" + new String(wenjiantitle.getBytes(), "iso8859-1") + ".xls");// 设定输出文件头
            response.setContentType("application/vnd.ms-excel");// 定义输出类型
            wbook = Workbook.createWorkbook(os); // 建立excel文件
            WritableSheet wsheet = wbook.createSheet(tmptitle, 0); // sheet名称
            // 设置excel标题
            WritableFont wfont = new WritableFont(WritableFont.ARIAL, 16, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式

            WritableCellFormat wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN); // 添加边框
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);

            WritableCellFormat wcfFC3 = new WritableCellFormat(wfont);
            wcfFC3.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC3.setAlignment(Alignment.CENTRE);
            //wcfFC.setBackground(Colour.AQUA);
            Label label=new Label(0, 0, tmptitle, wcfFC3);

            WritableCellFormat cellFormat = new WritableCellFormat();
            cellFormat.setAlignment(jxl.format.Alignment.CENTRE);
            cellFormat.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);
            cellFormat.setWrap(true);
            //cellFormat.setBackground(Colour.AQUA);
            cellFormat.setFont(wfont);
            label.setCellFormat(cellFormat);
            wsheet.addCell(label);
            wsheet.addCell(new Label(0, 0, tmptitle, wcfFC3));
            wsheet.setRowView(0,800); //第一行高度
            wsheet.setRowView(1,500); //第二行高度
            wsheet.mergeCells(0, 0, 25, 0);  //合并单元格(第一列的第一行和第十三列的第一行合并)
            wsheet.setColumnView(0,5); //品种宽度
            wsheet.setColumnView(1,10); //分类宽度
            wsheet.setColumnView(2,10); //品名宽度
            wsheet.setColumnView(3,5); //剂型宽度
            wsheet.setColumnView(4,5); //序号宽度
            wsheet.setColumnView(5,12); //名称宽度
            wsheet.setColumnView(6,10); //规格单位
            wsheet.setColumnView(7,5); //单位类别
            wsheet.setColumnView(8,5); //医保宽度
            wsheet.setColumnView(9,5); //1宽度
            wsheet.setColumnView(10,5); //2宽度
            wsheet.setColumnView(11,5); //3宽度
            wsheet.setColumnView(12,5); //1宽度
            wsheet.setColumnView(13,5); //2宽度
            wsheet.setColumnView(14,5); //3宽度
            wsheet.setColumnView(15,5); //4宽度
            wsheet.setColumnView(16,6); //1宽度
            wsheet.setColumnView(17,5); //2宽度
            wsheet.setColumnView(18,4); //基药宽度
            wsheet.setColumnView(19,4); //集采宽度
            wsheet.setColumnView(20,4); //1宽度
            wsheet.setColumnView(21,4); //2宽度
            wsheet.setColumnView(22,11); //产品宽度
            wsheet.setColumnView(23,12); //生产企业宽度
            wsheet.setColumnView(24,10); //委员表决票数宽度
            wsheet.setColumnView(25,10); //宽度
            // 开始生成主体内容
            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);
            // 不需要边框和居中的样式
            WritableFont wfont2 = new WritableFont(WritableFont.ARIAL, 8,WritableFont.BOLD,false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK); //设置表格样式
            WritableCellFormat wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setVerticalAlignment(jxl.format.VerticalAlignment.CENTRE);// 垂直居中
            wcfFC2 = new WritableCellFormat(wfont2);
            wcfFC2.setWrap(true);



            wsheet.addCell(new Label(13, 1, "日期:"+StringHandle.shorttiemString(),wcfFC2));
            wsheet.mergeCells(13, 1, 25, 1);


            wsheet.addCell(new Label(0, 2, "品种序号",wcfFC));
            wsheet.mergeCells(0, 2, 0, 3);
            wsheet.addCell(new Label(1, 2, "药品分类",wcfFC));
            wsheet.mergeCells(1, 2, 1, 3);
            wsheet.addCell(new Label(2, 2, "药品品名",wcfFC));
            wsheet.mergeCells(2, 2, 2, 3);
            wsheet.addCell(new Label(3, 2, "剂型",wcfFC));
            wsheet.mergeCells(3, 2, 3, 3);
            wsheet.addCell(new Label(4, 2, "序号",wcfFC));
            wsheet.mergeCells(4, 2, 4, 3);
            wsheet.addCell(new Label(5, 2, "药品名称",wcfFC));
            wsheet.mergeCells(5, 2, 5, 3);
            wsheet.addCell(new Label(6, 2, "规格",wcfFC));
            wsheet.mergeCells(6, 2, 6, 3);
            wsheet.addCell(new Label(7, 2, "单位",wcfFC));
            wsheet.mergeCells(7, 2, 7, 3);
            wsheet.addCell(new Label(8, 2, "医保类别",wcfFC));
            wsheet.mergeCells(8, 2, 8, 3);

            wsheet.addCell(new Label(9, 2, "上级检查通报",wcfFC));
            wsheet.addCell(new Label(10, 2, "未挂网",wcfFC));
            wsheet.addCell(new Label(11, 2, "无配送企业",wcfFC));

            wsheet.addCell(new Label(12, 2, "原国谈",wcfFC));
            wsheet.addCell(new Label(13, 2, "通过一致性评价",wcfFC));
            wsheet.addCell(new Label(14, 2, "国家保密配方",wcfFC));
            wsheet.addCell(new Label(15, 2, "中药保护品种",wcfFC));

            wsheet.addCell(new Label(16, 2, "价格（元）",wcfFC));
            wsheet.addCell(new Label(17, 2, "原研",wcfFC));

            wsheet.addCell(new Label(18, 2, "基药",wcfFC));
            wsheet.mergeCells(18, 2, 18, 3);
            wsheet.addCell(new Label(19, 2, "集采",wcfFC));
            wsheet.mergeCells(19, 2, 19, 3);
            wsheet.addCell(new Label(20, 2, "院本部",wcfFC));
            wsheet.mergeCells(20, 2, 19, 3);
            wsheet.addCell(new Label(21, 2, "秦淮",wcfFC));
            wsheet.mergeCells(21, 2, 21, 3);
            wsheet.addCell(new Label(22, 2, "产品编码",wcfFC));
            wsheet.mergeCells(22, 2, 22, 3);
            wsheet.addCell(new Label(23, 2, "生产企业",wcfFC));
            wsheet.mergeCells(23, 2, 23, 3);
            wsheet.addCell(new Label(24, 2, "委员表决票数",wcfFC));
            wsheet.mergeCells(24, 2, 24, 3);
            wsheet.addCell(new Label(25, 2, "表决结果",wcfFC));
            wsheet.mergeCells(25, 2, 25, 3);


            // 第四行内容
            wsheet.addCell(new Label(9, 3, "淘汰原则",wcfFC));
            wsheet.mergeCells(9, 3, 11, 3);
            wsheet.addCell(new Label(12, 3, "绝对优先",wcfFC));
            wsheet.mergeCells(12, 3, 15, 3);
            wsheet.addCell(new Label(16, 3, "相对优先",wcfFC));
            wsheet.mergeCells(16, 3, 17, 3);


            // 表头结束

            wfont = new jxl.write.WritableFont(WritableFont.ARIAL, 8, WritableFont.NO_BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BLACK);
            wcfFC = new WritableCellFormat(wfont);
            wcfFC.setBorder(jxl.format.Border.ALL, jxl.format.BorderLineStyle.THIN);
            wcfFC.setVerticalAlignment(VerticalAlignment.CENTRE);   //设置居中对齐
            wcfFC.setAlignment(Alignment.CENTRE);
            wcfFC.setWrap(true);


            int mmKaishihang1 = 4;
            int mmKaishihang2 = 4;
            int mmKaishihang3 = 4;


            int a=1;
            for (Map<String, Object> mmPinzhongMap : mmPinzhongAll) {

                int mmPinzhongHebingshu = 0;
                String mmPinzhongOne = mmPinzhongMap.get("pinzhongbianhao").toString();
                String mmYaopinpinming = mmPinzhongMap.get("yaopinpinming").toString();
                String mmbeizhu1 = mmPinzhongMap.get("beizhu1").toString();


                List<Map<String,Object>> mmPinguilist = ddShengchanqiyelinxuanService.findPinguiByPinzhong(ppxiangmuId,mmPinzhongOne);
                if (mmPinguilist.size()>0){
                    mmPinzhongHebingshu = mmPinguilist.size()-1;
                }
                List<Map<String,Object>> mmPinguiFenlei = ddShengchanqiyelinxuanService.findPinguiFenlei(ppxiangmuId,mmPinzhongOne);

                for (Map<String, Object> mmPinguiMap : mmPinguiFenlei) {

                    a=a+1;
                    String mmPinguiOne = mmPinguiMap.get("pinguixuhao").toString();
                    String mmYaopinmingcheng = mmPinguiMap.get("yaopinmingcheng").toString();
                    String mmGuige = mmPinguiMap.get("guige").toString();
                    String mmDanwei = mmPinguiMap.get("danwei").toString();
                    String mmYibaoleibie = mmPinguiMap.get("yibaoleibie").toString();
                    String mmjixing = mmPinguiMap.get("jixing").toString();

                    int mmHebingshu = 0;

                    List<Map<String,Object>> mmShengchanqiyelist = ddShengchanqiyelinxuanService.findShengchanqiyeByPinguiScore(ppxiangmuId,mmPinguiOne/*,mmLunci*/);
                    if (mmShengchanqiyelist.size()>0){
                        mmHebingshu = mmShengchanqiyelist.size()-1;
                    }
                    int pg=0;
                    for (Map<String, Object> mmMap : mmShengchanqiyelist) {
                        pg=pg+1;

                        String mmjianchatongbao = mmMap.get("jianchatongbao")==null ? "" :mmMap.get("jianchatongbao").toString();
                        String mmweiguawang=mmMap.get("weiguawang")==null ? "" :mmMap.get("weiguawang").toString();
                        String mmwupeisongqiye=mmMap.get("wupeisongqiye")==null ? "" :mmMap.get("wupeisongqiye").toString();
                        String mmyuanguotan=mmMap.get("yuanguotan")==null ? "" :mmMap.get("yuanguotan").toString();
                        String mmyizhixingpingjia=mmMap.get("yizhixingpingjia")==null ? "" :mmMap.get("yizhixingpingjia").toString();
                        String mmbaomipeifang=mmMap.get("baomipeifang")==null ? "" :mmMap.get("baomipeifang").toString();
                        String mmbaohupinzhong=mmMap.get("baohupinzhong")==null ? "" :mmMap.get("baohupinzhong").toString();
                        String mmjiage=mmMap.get("jiage")==null ? "" :mmMap.get("jiage").toString();
                        String mmyuanyan=mmMap.get("yuanyan")==null ? "" :mmMap.get("yuanyan").toString();
                        String mmjiyao=mmMap.get("jiyao")==null ? "" :mmMap.get("jiyao").toString();
                        String mmjicai=mmMap.get("jicai")==null ? "" :mmMap.get("jicai").toString();
                        String mmyuanbenbu=mmMap.get("yuanbenbu")==null ? "" :mmMap.get("yuanbenbu").toString();
                        String mmqinhuai=mmMap.get("qinhuai")==null ? "" :mmMap.get("qinhuai").toString();
                        String mmchanpinbianma=mmMap.get("chanpinbianma")==null ? "" :mmMap.get("chanpinbianma").toString();
                        String mmshengchanqiye=mmMap.get("shengchanqiye")==null ? "" :mmMap.get("shengchanqiye").toString();
                        String mmscore=mmMap.get("score")==null ? "" :mmMap.get("score").toString();
                        String mmstatus=mmMap.get("status")==null ? "" :mmMap.get("status").toString();
                        String mmtext = String.valueOf(mmscore) + "/" + String.valueOf(mmUserList.size());
                        String mmjieguo="";
                        if("1".equals(mmstatus)){
                            mmjieguo="通过";
                        }else {
                            mmjieguo="不通过";
                        }

                        WritableCellFormat alignStyle = new WritableCellFormat(); //单元格样式
                        alignStyle.setBackground(Colour.GREEN); //背静色

                        wsheet.addCell(new Label(9, mmKaishihang3,mmjianchatongbao,wcfFC));
                        wsheet.addCell(new Label(10, mmKaishihang3,mmweiguawang,wcfFC));
                        wsheet.addCell(new Label(11, mmKaishihang3,mmwupeisongqiye,wcfFC));
                        wsheet.addCell(new Label(12, mmKaishihang3,mmyuanguotan,wcfFC));
                        wsheet.addCell(new Label(13, mmKaishihang3,mmyizhixingpingjia,wcfFC));
                        wsheet.addCell(new Label(14, mmKaishihang3,mmbaomipeifang,wcfFC));
                        wsheet.addCell(new Label(15, mmKaishihang3,mmbaohupinzhong,wcfFC));
                        wsheet.addCell(new Label(16, mmKaishihang3,mmjiage,wcfFC));
                        wsheet.addCell(new Label(17, mmKaishihang3,mmyuanyan,wcfFC));
                        wsheet.addCell(new Label(18, mmKaishihang3,mmjiyao,wcfFC));
                        wsheet.addCell(new Label(19, mmKaishihang3,mmjicai,wcfFC));
                        wsheet.addCell(new Label(20, mmKaishihang3,mmyuanbenbu,wcfFC));
                        wsheet.addCell(new Label(21, mmKaishihang3,mmqinhuai,wcfFC));
                        wsheet.addCell(new Label(22, mmKaishihang3,mmchanpinbianma,wcfFC));
                        wsheet.addCell(new Label(23, mmKaishihang3,mmshengchanqiye,wcfFC));
                        wsheet.addCell(new Label(24, mmKaishihang3,mmtext,wcfFC));
                        wsheet.addCell(new Label(25, mmKaishihang3,mmjieguo,wcfFC));
                        mmKaishihang3 = mmKaishihang3+1;
                    }
                    wsheet.addCell(new Label(3, mmKaishihang2, mmjixing,wcfFC));
                    wsheet.addCell(new Label(4, mmKaishihang2, mmPinguiOne,wcfFC));
                    wsheet.addCell(new Label(5, mmKaishihang2, mmYaopinmingcheng,wcfFC));
                    wsheet.addCell(new Label(6, mmKaishihang2, mmGuige,wcfFC));
                    wsheet.addCell(new Label(7, mmKaishihang2, mmDanwei,wcfFC));
                    wsheet.addCell(new Label(8, mmKaishihang2, mmYibaoleibie,wcfFC));
                    wsheet.mergeCells(3, mmKaishihang2, 3, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(4, mmKaishihang2, 4, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(5, mmKaishihang2, 5, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(6, mmKaishihang2, 6, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(7, mmKaishihang2, 7, mmKaishihang2+mmHebingshu);
                    wsheet.mergeCells(8, mmKaishihang2, 8, mmKaishihang2+mmHebingshu);
                    mmKaishihang2 = mmKaishihang2+mmHebingshu+1;
                }
                wsheet.addCell(new Label(0, mmKaishihang1, mmPinzhongOne,wcfFC));
                wsheet.mergeCells(0, mmKaishihang1, 0, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(1, mmKaishihang1, mmbeizhu1,wcfFC));
                wsheet.mergeCells(1, mmKaishihang1, 1, mmKaishihang1+mmPinzhongHebingshu);
                wsheet.addCell(new Label(2, mmKaishihang1, mmYaopinpinming,wcfFC));
                wsheet.mergeCells(2, mmKaishihang1, 2, mmKaishihang1+mmPinzhongHebingshu);
                mmKaishihang1 = mmKaishihang1+mmPinzhongHebingshu+1;

            }
            wbook.write(); // 写入文件
            wbook.close();
        } catch(Exception ex)
        {
            ex.printStackTrace();
        }finally{
            if(os!=null){
                try {
                    os.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
    }

}
